﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Xml.Serialization;
using Cubicle.Core.Config;

namespace Cubicle.Excel.Config
{
    [Serializable]
    [PartCreationPolicy(CreationPolicy.Shared)]
    [XmlRoot(ElementName = "config")]
    public class ExcelConfig : BaseConfig
    {

        [Export]
        public static ExcelConfig Create
        {
            get { return Read<ExcelConfig>(); }
        }

        [XmlElement(ElementName = "link")]
        public List<LinkConfig> Links;

        [XmlElement(ElementName = "eventServer")]
        public List<EventServerConfig> EventServers;

        [XmlElement(ElementName = "assembly", IsNullable = true)]
        public List<string> Assemblies;

        [XmlAttribute(AttributeName = "registerExplicit")]
        public bool RegisterExplicit;

        [XmlAttribute(AttributeName = "autoRegisterFunctions")]
        public bool AutoRegisterFunctions;

    }

    [Serializable]
    [XmlRoot(ElementName = "link")]
    public class LinkConfig
    {

        [XmlAttribute(AttributeName = "alias")]
        public string Alias;

        [XmlAttribute(AttributeName = "isDefault")]
        public bool IsDefault;

        [XmlAttribute(AttributeName = "address")]
        public string Address;

    }

    [Serializable]
    [XmlRoot(ElementName = "eventServer")]
    public class EventServerConfig
    {

        [XmlAttribute(AttributeName = "alias")]
        public string Alias;

        [XmlAttribute(AttributeName = "address")]
        public string Address;

        [XmlAttribute(AttributeName = "clientServerName")]
        public string HttpClientServerName;

        [XmlAttribute(AttributeName = "httpPort")]
        public int HttpPort;

        [XmlAttribute(AttributeName = "identifier")]
        public string Identifier;

    }

}
